<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 【案例】使用reduce实现数组去重 -->
    <script>
        var arr1 = [1, 2, 2, 3, 4, 5];
        // var arr2 = [];
        var res = arr1.reduce(function (pre, cur) {
            if (pre.indexOf(cur) === -1) {
                return pre.concat(cur)
            } else {
                return pre
            }
        }, [])
    </script>
</body>

</html>